package cxf.services.restful;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import cxf.bean.ArrayBean;

@Path("/restservice")
public class RESTService implements IRESTService {
	  @GET // The HTTP method by which we access the service 
	  @Produces(MediaType.TEXT_HTML) // The output MIME Type 
	  public String getMethod() 
	  { 
	     return "<b>Hello World, Welcome to Jersey + Spring Integrattion</b>"; 
	  }
	  
	  @Path("{name}/{age}")
	  @GET
	  @Produces(MediaType.TEXT_PLAIN)
	  public String addString(@PathParam("name") String name, @PathParam("age") int age) {
		  return "hello : " + name + " " + age;
	  }
	  
	  @Path("/query")
	  @GET
	  @Produces(MediaType.TEXT_PLAIN)
	  public String query(@QueryParam("name") String name, @QueryParam("age") int age) {
		  return "query - " + name + ":" + age;
	  }
	  
	  
	  @POST
	  @Path("/json")
	  @Consumes(MediaType.APPLICATION_JSON)
	  @Produces(MediaType.APPLICATION_JSON)
	  public String getSimpleJSON(ArrayBean bean) {
		  return bean.getName() + " " + bean.getBeans().size();
//		  return "hello";
	  }
	  
	  @POST
	  @Path("/form")
	  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	  @Produces(MediaType.TEXT_PLAIN)
	  public String getSimpleJSON(@FormParam("name") String name, @FormParam("age") String age) {
		  return "form - " + name + ":" + age;
//		  return "hello";
	  }
}
